<template>
	<view>
		<view-topbb></view-topbb>

		<view class="city">

			<!-- 搜索 -->
			<view class="ss">

				<view class="inp">
					<input @confirm="toSearch" v-model="keyword" type="text" placeholder="请输入地级市进行搜索">
					<view @click="toSearch" class="inp-icon">
						<image src="/static/images/ss.png" mode="widthFix"></image>
					</view>
				</view>


				<view class="xuanze">
					<view class="ti1" @click="fanhw">
						{{province || '省'}}
					</view>
					<view class="jiant">
						>
					</view>
					<view class="ti1">
						{{city || '市'}}
					</view>
				</view>
			</view>



			<view class="csxx" v-if="info.title">
				<view class="ty1">
					{{info.title}}
				</view>

				<view class="ty2" v-if="info.articleData">
					<u-parse :content="info.articleData.content"></u-parse>
					<!-- 					<view class="boxt">

						<text>加盟热线</text>
						13381489433
					</view>
					<view class="boxt">
						<text>联系地址</text>
						北京市丰台区南三环中路刘家窑桥西16号底楼前154号
						(果多美刘家窑店二楼)
					</view> -->
				</view>
			</view>
			<view class="csxx" v-else>
				<view class="ty2">
				未找到{{showKeyword}}，请输入行政省下一级城市搜索，或点击左上角“省-市”进行查找
			</view></view>


			<!-- <view-tabbar :current="3"></view-tabbar> -->
		</view>

	</view>
</template>

<script>
	import topbb from '@/components/topbb.vue'
	import Tabbar from '@/components/tabbar.vue'
	// 导入省市数据
	import cityData from '@/components/map/cityData.js';
	// 导入热门城市数据
	import hotData from '@/components/map/hotData.js'


	export default {
		data() {
			return {
				// 省市数据
				province: '',
				city: '',
				keyword: '',
				// 侧边导航选项索引
				indexsp: '0',
				showKeyword:'',
				// 选中城市数组
				current: [],
				info: {},
				// 热门城市数据
				hotlist: hotData
			};
		},
		onShareAppMessage() {},
		onShareTimeline() {},
		onLoad(e) {
			let that = this;
			// 将页面传递过来的数据使用"|"符号分割开,存储到变量current中
			// that.current = e.city ? e.city.split('|') : [];
			if (e.id) {
				that.$api.article_data({
					articleId: e.id
				}, res => {
					if (res.code == 200) {
						that.info = res.data
						let area = that.info.area.treeNames.split('/')
						that.province = area[0]
						that.city = area[1]
					}
				})
			}
			if (e.keyword) {
				this.keyword = e.keyword
				this.toSearch()
			}
		},
		components: {
			'view-topbb': topbb,
			'view-tabbar': Tabbar,
		},
		onShow() {
			uni.hideTabBar({
				animation: false
			})
		},
		methods: {
			toSearch() {
				this.info ={}
				this.province =''
				this.city = ''
				this.showKeyword=JSON.parse(JSON.stringify(this.keyword))
				this.$api.article_list_data({
					siteCode: 'main',
					categoryCode: 1004004,
					cityName: this.keyword
				}, res => {
					if (res.code == 200) {
						if (res.data.count) {

							this.info = res.data.list[0]
							let area = this.info.area.treeNames.split('/')
							this.province = area[0]
							this.city = area[1]
						}
					}
				})
			},
			indexOfs(list, name) {
				return list.indexOf(name) != -1;
			},
			setCity(city) { // city 当前点击的城市

				let that = this;
				// 选中的城市数组
				let current = that.current;
				// 将当前点击城市在选中城市数组中检索,将结果赋值给变量index
				let index = current.indexOf(city);
				// if (city == '不限') {
				// 	that.current = [city];
				// } else 
				if (index != -1) {
					//index不等于-1代表选中数组中已有当前点击城市
					//从返回的城市数组位置进行删除一个元素
					that.current.splice(index, 1)

				} else if (current.length < 4) {
					// 当选中的城市数少于4个时
					// let indexs = that.current.indexOf('不限');
					// indexs > -1 ? that.current.splice(indexs, 1) : '';
					// 将当前点击城市push进选中城市数组
					that.current.push(city);
				} else { //弹窗提示,选中城市不能超过4个
					uni.showToast({
						title: '城市不能超过4个',
						icon: 'none'
					})
				}
			},
			// 确定按钮触发函数
			back() {
				// 将数据通过|符号切割开
				let city = this.current.join('|');
				// 组件传值
				uni.$emit('setCity', city);
				// 返回上一个页面
				uni.navigateBack({
					delta: 1
				})
			},
			fanhw() {
				uni.switchTab({
					url: '/pages/zixun/index',
				})
			},
		}
	}
</script>


<style lang="scss" scoped>
	.submit {
		position: fixed;
		bottom: 10rpx;
		width: 500rpx
	}

	.f08btn {
		// background-color: #f08300 !important;
		// color: #fff;
		font-size: 28rpx;
	}

	.city {
		width: 100%;
		margin-top: -20rpx;
		position: fixed;

		&_title {
			margin-bottom: 60rpx;
		}

		&_item {
			padding-bottom: 20rpx;
			align-items: flex-start;

			&_left {
				width: 210rpx;
				display: inline-block;
				background: #fff;

				view {
					text-align: center;
					padding: 20rpx;
					font-size: 28rpx;
				}

				.active {
					color: #00943a;
					background: #f3f5f7;
				}
			}

			&_right {
				width: 500rpx;
				display: inline-block;
				padding-left: 20rpx;
				position: fixed;
				overflow: scroll;
				height: 68vh;


				button {
					border: 1rpx solid #f6f6f6;
				}

				.current {
					padding: 20rpx 30rpx 0 0;

					// 当前城市样式
					.hot_title {
						width: 100%;
						display: inline-block;
						color: #555;
						line-height: 1;
						vertical-align: middle;
						margin-bottom: 22rpx;
						font-size: 30rpx;
					}

					.flex1 {
						color: orange;

						.data-v-57280228 {}

						text {
							font-size: 14px;
						}
					}

					.icon {
						width: 30rpx;
						height: 35rpx;
						display: inline-block;
						vertical-align: middle;
					}

					view {

						justify-content: space-between;

						view {
							width: calc(100% - 40rpx);

							text {
								display: inline-block;
							}
						}
					}
				}

				.hot {
					button {
						color: #555555;
						width: 100%;
						height: 65rpx;
						background: transparent;
						padding: 0 12rpx;
						display: inline-block;
						font-size: 30rpx;
						text-align: left;
						margin: 18rpx 20rpx 0 0;
					}

					button:after {
						border-color: #eee;
					}

					// .active {
					// 	color: #f08300;
					// 	border: 1rpx solid #f08300;
					// }

					// .active:after {
					// 	border-color: #f08300;
					// }

				}
			}
		}

	}

	.ss {
		margin: auto;
		background: #fff;

		.inp {
			position: relative;
			border-radius: 50rpx;
			margin: auto;

			
			.inp-icon{
				
					width: 100rpx;
				position: absolute;
				z-index: 2;
				right:40rpx;
				top: 0;
				bottom: 0rpx;
				margin: auto;
				display: flex;
				align-items: center;
				justify-content: center;
			}
			image {
				width: 30rpx;
			
			}

			input {
					font-size: 28rpx;
				background: #f3f5f7;
				width: 85%;
				margin: auto;
				padding: 20rpx 20rpx;
				border-radius: 50rpx;
				margin-top: 20rpx;
				margin-bottom: 0rpx;
				line-height: 1.7;



			}
		}

		.xuanze {

			width: 85%;
			margin: auto;
			display: flex;
			align-items: center;
			font-size: 30rpx;
			padding: 20rpx 0;
			color: #00943a;

		}
	}

	.ti1 {
		margin-right: 10rpx;
	}

	.jiant {
		margin: 0 10rpx;
	}

	.csxx {
		background: #fff;
		padding: 40rpx;
		margin: 20rpx 30rpx;
		border-radius: 30rpx;

		.ty1 {
			font-size: 32rpx;
			font-weight: bold;
			color: #00943a;
			margin-bottom: 30rpx;
		}

		.ty2 {
			font-size: 26rpx;
			color: #555555;
			line-height: 1.7;

			.boxt {
				display: block;
				width: 100%;
				margin-bottom: 20rpx;
			}

			text {
				color: #00943a;
				display: block;
				margin-bottom: 10rpx;
				width: 100%;
			}
		}
	}
</style>